{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn\n",
    "import argoverse\n",
    "import os\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from argoverse.map_representation.map_api import ArgoverseMap\n",
    "am = ArgoverseMap()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "laneid_map = {}\n",
    "city_halluc_bbox_table, city_halluc_tableidx_to_laneid_map = am.build_hallucinated_lane_bbox_index()\n",
    "for key in city_halluc_tableidx_to_laneid_map['PIT']:\n",
    "    laneid_map[city_halluc_tableidx_to_laneid_map['PIT'][key]] = key\n",
    "# print(laneid_map[9604252])\n",
    "# am.draw_lane(9605254,'PIT')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[3169.32205386 1673.23812102   12.06078911]\n",
      " [3168.23790046 1672.28332305   12.06012726]\n",
      " [3167.15374705 1671.32852508   12.05201435]\n",
      " [3166.06958947 1670.37372343   12.04936886]\n",
      " [3164.98541611 1669.41891914   12.08331203]\n",
      " [3163.90123323 1668.46413401   12.12041378]\n",
      " [3162.81706055 1667.50935785   12.12357044]\n",
      " [3161.73288786 1666.55458169   12.11620617]\n",
      " [3160.64871518 1665.59980553   12.13007832]\n",
      " [3159.5645425  1664.64502937   12.14779472]\n",
      " [3157.05311276 1667.4968219    12.10913754]\n",
      " [3158.13728544 1668.45159806   12.11946487]\n",
      " [3159.22145812 1669.40637422   12.1274004 ]\n",
      " [3160.3056308  1670.36115038   12.21748352]\n",
      " [3161.38980349 1671.31592654   12.22270489]\n",
      " [3162.47396598 1672.27069372   12.20272446]\n",
      " [3163.55811061 1673.22547271   12.13764477]\n",
      " [3164.64225985 1674.18026701   12.1427393 ]\n",
      " [3165.72641325 1675.13506498   12.14144802]\n",
      " [3166.81056666 1676.08986295   12.06586075]\n",
      " [3169.32205386 1673.23812102   12.06078911]]\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"100.0\" height=\"100.0\" viewBox=\"3156.56235511159 1667.006064259977 13.25045639281825 9.574556329410598\" preserveAspectRatio=\"xMinYMin meet\"><g transform=\"matrix(1,0,0,-1,0,3343.5866848493642)\"><path fill-rule=\"evenodd\" fill=\"#66cc99\" stroke=\"#555555\" stroke-width=\"0.265009127856365\" opacity=\"0.6\" d=\"M 3157.0531127557683,1667.4968219041555 L 3158.1372854386623,1668.4515980631975 L 3159.221458121556,1669.4063742222397 L 3160.305630804451,1670.3611503812815 L 3161.3898034873446,1671.3159265403233 L 3162.4739659751376,1672.2706937209894 L 3163.5581106113264,1673.2254727077766 L 3164.6422598459894,1674.180267005019 L 3165.726413251113,1675.135064975114 L 3166.810566656236,1676.089862945209 L 3169.32205386023,1673.238121017163 L 3157.0531127557683,1667.4968219041555 z\" /></g></svg>"
      ],
      "text/plain": [
       "<shapely.geometry.polygon.Polygon at 0x7f0381283e10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"100.0\" height=\"100.0\" viewBox=\"650.7353604038834 -20.82410507745988 6.6863030267787735 2.514155251507219\" preserveAspectRatio=\"xMinYMin meet\"><g transform=\"matrix(1,0,0,-1,0,-39.13405490341254)\"><path fill-rule=\"evenodd\" fill=\"#66cc99\" stroke=\"#555555\" stroke-width=\"0.13372606053557548\" opacity=\"0.6\" d=\"M 650.9830012567271,-20.576464224616224 L 654.0733627191411,-19.546953814771317 L 657.1740225778185,-18.557590678796316 L 650.9830012567271,-20.576464224616224 z\" /></g></svg>"
      ],
      "text/plain": [
       "<shapely.geometry.polygon.Polygon at 0x7f034fdbde10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from shapely.geometry.polygon import Polygon\n",
    "print(am.find_local_lane_polygons([3167-20,3167+20,1673-20,1673+20], 'PIT')[0])\n",
    "display(Polygon(am.find_local_lane_polygons([3167-20,3167+20,1673-20,1673+20], 'PIT')[0][10:21]))\n",
    "display(Polygon(am.get_lane_segment_polygon(9610257, 'PIT')[3:6]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:sassd] *",
   "language": "python",
   "name": "conda-env-sassd-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
